using System;
using System.Windows.Forms;

namespace Just4Devs.Vsirc.Addin.UI
{
    /// <summary>
    /// A control responsible for displaying a chat screen with the controls
    /// to the IRC client.
    /// </summary>
    public partial class VsircMainControl : UserControl
    {
        #region Fields

        private VsircScreenDirector _screenDirector;

        #endregion

        #region Constructors

        public VsircMainControl()
        {
            InitializeComponent();
        }

        #endregion

        private void VsircAddin_Load(object sender, EventArgs e)
        {
            _screenDirector = new VsircScreenDirector(ircTabControl);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var message = sendMessageTextBox.Text;

            if (!string.IsNullOrEmpty(message))
            {
                _screenDirector.RequestMessageDispatch(message);
                sendMessageTextBox.Clear();
            }
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                e.Handled = true;
                button1_Click(sendMessageTextBox, null);
            }
        }

        private void commandConnect_Click(object sender, EventArgs e)
        {
            _screenDirector.RequestConnect();
        }

        private void commandDisconnect_Click(object sender, EventArgs e)
        {
            _screenDirector.RequestDisconnect();
        }

        private void commandTest_Click(object sender, EventArgs e)
        {

        }

        private void ircTabControl_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.W)
            {
                _screenDirector.CloseCurrentTab();
            }
        }


    }
}
